<template>
  <div
    class="zui-field"
    :class="{
      'label-position-top': labelPosition == 'top',
      round,
      shadow: showShadow,
      padding,
      clickable,
      'fade-label': fadeLabel && value
    }"
    :style="style"
  >
    <h1
      v-if="!hideLabel"
      class="label-wrap"
      :class="[labelStyle, label ? 'label-min-width' : '']"
      :style="{ color: labelColor }"
    >
      <label>{{ label }}</label
      ><span v-if="required" class="required">*</span>
    </h1>
    <slot name="accessory">
      <div class="accessory">
        <span class="value-wrap">
          <h5 v-if="value" class="value">{{ value }}</h5>
          <span v-else class="placeholder">{{ placeholder }}</span>
        </span>

        <i v-if="showArrowRight" class="arrow-right iconfont-zui icon-zui-arrow-right-round" />
      </div>
    </slot>
  </div>
</template>

<script setup lang="ts">
const props = defineProps({
  round: Boolean,
  showShadow: Boolean,
  // 内边距
  padding: String,
  hideLabel: Boolean,
  // label 位置 top/left
  labelPosition: {
    type: String,
    default: 'left'
  },
  clickable: {
    type: Boolean,
    default: true
  },
  label: String,
  labelColor: {
    type: String,
    default: ''
  },
  // 标签样式 weak/normal/strong/xstrong
  labelStyle: {
    type: String,
    default: 'strong'
  },
  required: Boolean,
  fadeLabel: Boolean,
  value: [String, Number, Boolean],
  placeholder: String,
  showArrowRight: {
    type: Boolean,
    default: true
  }
})

const style = { padding: props.padding || '12px 20px' }
</script>

<style lang="scss" scoped>
.zui-field {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  background: #ffffff;
  &.label-position-top {
    flex-direction: column;
    align-items: flex-start;

    .accessory {
      margin-top: 8px;
      width: 100%;
      justify-content: space-between;
      .value-wrap {
        justify-content: space-between;
      }
    }
  }
  &.round {
    border-radius: var(--zui-size-border-radius-regular);
  }
  &.shadow {
    box-shadow: var(--zui-box-shadow);
  }
  &.clickable:active {
    background: rgba($color: #ffffff, $alpha: 0.49);
  }

  &.fade-label {
    .left {
      h1 {
        font-size: var(--zui-size-text-regular);
        color: var(--zui-color-text-secondary);
        font-weight: normal;
      }
    }
    .accessory {
      h5 {
        font-size: var(--zui-size-text-large);
      }
    }
  }
  .label-wrap {
    text-align: left;
    transition: all 0.2s ease-in-out;
    line-height: var(--zui-size-line-height-regular);
    font-size: var(--zui-size-text-regular);
    &.label-min-width {
      min-width: 30%;
    }
    &.strong {
      font-weight: bold;
      font-size: var(--zui-size-text-regular);
    }
    &.xstrong {
      font-weight: bold;
      font-size: var(--zui-size-text-large);
    }
    &.weak {
      color: var(--color-text-secondary);
    }
    .required {
      padding: 0 4px;
      color: var(--zui-color-red);
    }
  }
  .accessory {
    color: var(--zui-color-text-primary);
    flex: 1 auto;
    text-align: justify;
    text-align-last: left;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    .arrow-right {
      font-size: var(--zui-size-text-small);
      color: var(--zui-color-text-secondary);
      margin-left: 4px;
    }

    .placeholder {
      color: var(--zui-color-text-placeholder);
    }
  }
}
</style>
